﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using IronCow.UnitTests.Mock;

namespace IronCow.UnitTests
{
    [TestFixture]
    public class TestContacts
    {
        [Test]
        public void TestGetContactList()
        {
            MockRtm rtm = new MockRtm();
            rtm.AddSuccessResponse("rtm.contacts.getList",
                new MockContactsResponsePart()
                {
                    new MockContactResponsePart(1, "Omar Kilani", "omar")
                });
            
            Assert.AreEqual(1, rtm.Contacts.Count);
            Contact contact = rtm.Contacts[0];
            Assert.AreEqual("1", contact.Id);
            Assert.AreEqual("Omar Kilani", contact.FullName);
            Assert.AreEqual("omar", contact.UserName);
            Assert.IsTrue(contact.IsSynced);
        }

        [Test]
        public void TestAddContact()
        {
            MockRtm rtm = new MockRtm();
            rtm.AddSuccessResponse("rtm.contacts.getList", new MockContactsResponsePart());
            rtm.AddTimelineResponse();
            rtm.AddSuccessResponse("rtm.contacts.add", new MockContactResponsePart(1, "Omar Kilani", "omar"));
            
            Assert.AreEqual(0, rtm.Contacts.Count);            
            Contact contact = new Contact("omar");
            Assert.IsFalse(contact.IsSynced);

            rtm.Contacts.Add(contact);
            Assert.AreEqual(1, rtm.Contacts.Count);
            Assert.IsTrue(contact.IsSynced);
            Assert.AreSame(contact, rtm.Contacts[0]);
            Assert.AreEqual("Omar Kilani", contact.FullName);
            Assert.AreEqual("omar", contact.UserName);

            rtm.EnsureAllResponsesUsed();
        }

        [Test]
        public void TestRemoveContact()
        {
            MockRtm rtm = new MockRtm();
            rtm.AddSuccessResponse("rtm.contacts.getList",
                new MockContactsResponsePart()
                {
                    new MockContactResponsePart(1, "Omar Kilani", "omar")
                });
            rtm.AddTimelineResponse();
            rtm.AddSuccessResponse("rtm.contacts.delete");

            Assert.AreEqual(1, rtm.Contacts.Count);
            rtm.Contacts.Remove(rtm.Contacts[0]);
            Assert.AreEqual(0, rtm.Contacts.Count);

            rtm.EnsureAllResponsesUsed();
        }
    }
}
